package com.mystudy.leetcode.problem.other.p_1131;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @program: infoalgorithm
 * @description: 绝对值表达式的最大值
 * @author: zhouzhilong
 * @create: 2019-07-29 17:17
 **/
public class Solution {
    /** logger */
    private static final Logger LOGGER = LoggerFactory.getLogger(Solution.class);
    @Test
    public void test(){
        int [] arr1 = new int[]{1,2,3,4};
        int [] arr2 = new int[]{-1,4,5,6};
        int i = maxAbsValExpr(arr1, arr2);
        LOGGER.debug("i = [{}]",i);
    }



    //|arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|
    public int maxAbsValExpr(int[] arr1, int[] arr2) {
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < arr1.length; i++) {
            for (int j = i+1; j < arr1.length; j++) {
                int arr1Result = arr1[i]-arr1[j];
                int arr2Result = arr2[i]-arr2[j];
                int ijResult = i - j;

                LOGGER.debug("-----------------------------");
                LOGGER.debug("arr1Result = [{}]",arr1Result);
                LOGGER.debug("arr2Result = [{}]",arr2Result);
                LOGGER.debug("ijResult = [{}]",ijResult);
                int m = ((arr1Result<0?-1*arr1Result:arr1Result) +(arr2Result<0?-1*arr2Result:arr2Result)+(ijResult<0?-1*ijResult:ijResult));
                LOGGER.debug("m = [{}]",m);
                LOGGER.debug("-----------------------------");
                if(m>max){
                    max = m;
                }

            }
        }
        return max;
    }
}
